package com.dqv5.k8s.bookinfo.service.impl;

import com.dqv5.k8s.bookinfo.repository.BookRepository;
import com.dqv5.k8s.bookinfo.entity.BookInfo;
import com.dqv5.k8s.bookinfo.service.BookService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author duqian
 * @date 2020/9/25
 */
@Service
public class BookServiceImpl implements BookService {
    @Resource
    private BookRepository bookRepository;

    @Override
    public List<BookInfo> queryAll() {
        return bookRepository.findAll();
    }

    @Override
    public BookInfo queryById(Long id) {
        return bookRepository.findById(id).orElseThrow(RuntimeException::new);
    }

    @Override
    public void insert(BookInfo bookInfo) {
        bookRepository.save(bookInfo);
    }

    @Override
    public void update(BookInfo bookInfo) {
        bookRepository.save(bookInfo);
    }

    @Override
    public void delete(Long id) {
        bookRepository.deleteById(id);
    }
}
